package org.test;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 经纬度坐标
 */
@Data
public class Point {
    /**
     * 经度。数值在正负180
     */
    private Double longitude;

    /**
     * 纬度。数值在正负90
     */
    private Double latitude;

    /**
     * 备注，说明
     */
    private String desc;


    public static Point parse(String longitude_latitude, String desc) {
        Point point = new Point(0D, 0D);
        point.longitude = Double.parseDouble(StringUtils.substringBefore(longitude_latitude, ",").trim());
        point.latitude = Double.parseDouble(StringUtils.substringAfter(longitude_latitude, ",").trim());
        point.desc = desc;

        if (Math.abs(point.longitude) > 180 || Math.abs(point.latitude) > 90) {
            throw new RuntimeException("异常");
        }
        return point;
    }

    public Point(Double latitude, Double longitude) {
        this.latitude = latitude;
        this.longitude = longitude;
    }

    public Point(Double latitude, Double longitude, String orderId) {
        this.latitude = latitude;
        this.longitude = longitude;
        this.desc = orderId;
    }

    @Override
    public String toString() {
        return "Point{" +
                "latitude='" + latitude + '\'' +
                ", longitude='" + longitude + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }

    /**
     * 返回
     *
     * @return
     */
    public String asString(String join) {
        return String.format("%s%s%s", this.latitude, join, this.longitude);
    }

    public static void main(String[] args) {
        Point point = new Point(114.465302D, 40.004717D);
        System.out.println(point.asString("|"));
        System.out.println(point.asString(","));
    }
}
